package labox.innovation.gameserver.skills.effects;

import labox.innovation.config.Config;
import labox.innovation.gameserver.ai.CtrlIntention;
import labox.innovation.gameserver.geodata.GeoData;
import labox.innovation.gameserver.model.L2CharPosition;
import labox.innovation.gameserver.model.L2Effect;
import labox.innovation.gameserver.model.Location;
import labox.innovation.gameserver.model.actor.instance.FuzeNpcInstance; //import labox.innovation.gameserver.model.actor.instance.L2FortCommanderInstance;
//import labox.innovation.gameserver.model.actor.instance.L2FortSiegeGuardInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance; //import labox.innovation.gameserver.model.actor.instance.L2PetInstance;
//import labox.innovation.gameserver.model.actor.instance.L2SiegeFlagInstance;
//import labox.innovation.gameserver.model.actor.instance.L2SiegeGuardInstance;
//import labox.innovation.gameserver.model.actor.instance.L2SiegeSummonInstance;
import labox.innovation.gameserver.skills.Env;
import labox.innovation.gameserver.templates.effects.EffectTemplate;
import labox.innovation.gameserver.templates.skills.L2EffectType;

/**
 * �־�Ч��
 * 
 * @author zjj
 * 
 */
public class EffectFear extends L2Effect {
	public static final int FEAR_RANGE = 500;

	private int _dX = -1;
	private int _dY = -1;

	public EffectFear(Env env, EffectTemplate template) {
		super(env, template);
	}

	/**
	 * 
	 * @see labox.innovation.gameserver.model.L2Effect#getEffectType()
	 */
	@Override
	public L2EffectType getEffectType() {
		return L2EffectType.FEAR;
	}

	/**
	 * 
	 * @see labox.innovation.gameserver.model.L2Effect#onStart()
	 */
	@Override
	public boolean onStart() {
		// Fear skills cannot be used l2pcinstance to l2pcinstance. Heroic
		// Dread, Curse: Fear, Fear, Horror, Sword Symphony, Word of Fear and
		// Mass Curse Fear are the exceptions.
		if (getEffected() instanceof FuzePcInstance && getEffector() instanceof FuzePcInstance && getSkill().getId() != 1376 && getSkill().getId() != 1169 && getSkill().getId() != 65 && getSkill().getId() != 1092 && getSkill().getId() != 98 && getSkill().getId() != 1272 && getSkill().getId() != 1381)
			return false;

		if (!(getEffected() instanceof FuzeNpcInstance))
			// || getEffected() instanceof L2SiegeGuardInstance
			// || getEffected() instanceof L2FortSiegeGuardInstance
			// || getEffected() instanceof L2FortCommanderInstance
			// || getEffected() instanceof L2SiegeFlagInstance
			// || getEffected() instanceof L2SiegeSummonInstance)
			return false;

		if (!getEffected().isAfraid()) {
			if (getEffected().getX() > getEffector().getX())
				_dX = 1;
			if (getEffected().getY() > getEffector().getY())
				_dY = 1;

			getEffected().startFear();
			onActionTime();
			super.onStart();
			return true;
		}
		return false;
	}

	/**
	 * 
	 * @see labox.innovation.gameserver.model.L2Effect#onExit()
	 */
	@Override
	public void onExit() {
		getEffected().stopFear(this);
		super.onExit();
	}

	/**
	 * 
	 * @see labox.innovation.gameserver.model.L2Effect#onActionTime()
	 */
	@Override
	public boolean onActionTime() {
		int posX = getEffected().getX();
		int posY = getEffected().getY();

		posX += _dX * FEAR_RANGE;
		posY += _dY * FEAR_RANGE;

		if (Config.GEODATA > 0) {
			// ��� ���־�� �ص��Ƿ�����
			// TODO:
			// Location destiny = GeoData.moveCheck(getEffected().getX(),
			// getEffected().getY(), posX, posY);
			// posX = destiny.getX();
			// posY = destiny.getY();
		}

		// if (!(getEffected() instanceof L2PetInstance))
		// getEffected().setRunning();

		getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY));
		return true;
	}
}
